package com.yimi.yinhepda.db.dao;

import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;
import com.pda.ym.utils.DateHelper;
import com.yimi.yinhepda.base.BaseApplication;
import com.yimi.yinhepda.db.helper.DbHelperTemp;
import com.yimi.yinhepda.db.table.DepartmentTable;
import com.yimi.yinhepda.db.table.LineVoTable;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/14
 * 线路表操作
 */
public class LineVoTableTempDao extends BaseDaoTemp<LineVoTable, Long> {

    public LineVoTableTempDao() {
        super(DbHelperTemp.getInstance(BaseApplication.getContext()), LineVoTable.class);
    }

    /**
     * 分页查询数据
     */
    public List<LineVoTable> findDataByPage(long currentPage, long pageSize, String currentDate) {
        try {
            QueryBuilder<LineVoTable, Long> queryBuilder = dao.queryBuilder();
            Where where = queryBuilder.where();
            where.and(
                    where.le("effectiveTime", currentDate),
                    where.ne("isDelete", 1),
                    where.or(
                            where.isNull("invalidTime"),
                            where.ge("invalidTime", currentDate)
                    )
            );
            return queryBuilder.offset(currentPage * pageSize).limit(pageSize).query();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public long findTotalSize(String currentDate) {
        try {
            QueryBuilder<LineVoTable, Long> queryBuilder = dao.queryBuilder();
            Where where = queryBuilder.where();
            where.and(
                    where.le("effectiveTime", currentDate),
                    where.ne("isDelete", 1),
                    where.or(
                            where.isNull("invalidTime"),
                            where.ge("invalidTime", currentDate)
                    )
            );
            return queryBuilder.countOf();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
